<?php
namespace org\kahikai\database\mysql;
use \mysqli;

/**
 * 
 * @author ch4mp
 *
 */
class KahikaiMysql {
	
	public static function query($queryString) {
		$mysqli = KahikaiMysql::getConnection();
		
		$result = $mysqli->query($queryString);
		
 		$mysqli->close();
		return $result;
	}
	
	public static function commit() {
		$mysqli = KahikaiMysql::getConnection();
		return $mysqli->commit();
	}
	
	public static function rollback() {
		$mysqli = KahikaiMysql::getConnection();
		return $mysqli->rollback();
	}
	
	public static function prepare($queryString) {
		$mysqli = KahikaiMysql::getConnection();
		
		$preparedStatment = $mysqli->prepare($queryString);
		if ($preparedStatment === FALSE) {
			printf("\"%s\" preparation failed: %s\n", $queryString, $mysqli->error);
		}
		
		return $preparedStatment;
	}
	
	public static function getConnection() {
		$mysqli = new mysqli("localhost", "kahikai", "kahiK@1", "kahikai");
		
		/* check connection */
		if ($mysqli->connect_errno) {
			printf("Connect failed: %s\n", $mysqli->connect_error);
			return false;
		}
		
		return $mysqli;
	}
}
?>